/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.bath.machine.neural3;

import uk.ac.bath.base.Value;

/**
 *
 * @author pjl
 */
public final class Neuron {

    final Value in[];
    final float w[];
    
    final private int n;
    final Value o;

    Neuron(Value in[], Float w[],Value o) {
        this.n=in.length;
        this.in = in;
        this.w=new float[n];
        
        for (int i = 0; i < w.length; i++) {
            this.w[i] = w[i];
        }
        this.o=o;
    }

    final void fire() {
        float sum = 0.0f;
        for (int i = 0; i < n; i++) {
            sum += w[i] * in[i].val;
        }
        o.val=sigmoid(sum);
    }


     public static final float sigmoid1(float in) {
        return (float) (1.0 / (1.0 + Math.exp(-in)));
    }

    public static final float sigmoid(float in) {
        return (float) (2.0 / (1.0 + Math.exp(-in))-1.0);
    }
}
